<template>
    <div>
        <!-- tab-top-webview-main -->
		<!-- 滑动导航 -->
       
		<div id="slider" class="mui-slider">
			<div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
				<div class="mui-scroll">
					<a v-for="item in cates" @tap ="getCategoryList(item.id)" :key="item.id" :class="['mui-control-item',item.id==0?'mui-active':'']" href="#item1mobile" data-wid="tab-top-subpage-1.html">
						{{item.title}}
					</a>
					
				</div>
			</div>
		</div>
		<!-- 图片内容区 -->
		<ul class="photo-list">
			<!-- tag="li" 的作用 让router-link 渲染的标签为li， 即在游览器下查看代码看到是li标签-->
			<router-link v-for="item in list" :key="item.id" :to="'/home/photolist/photoinfo/'+item.id" tag="li">
				<img v-lazy="item.img_url">
				<div class="info">
					<h1 class="info-title">{{item.title}}</h1>
					<div class="info-body">{{item.zhaiyao}}</div>
				</div>
			</router-link>
		</ul>
    </div>
</template>
<script>
//导入mui,需要移除严格模式
import mui from '../../lib/mui/js/mui.js'
import {Toast} from 'mint-ui';
export default {
	data(){
		return {
			cates:null,
			list:{}
		}
	},
	created(){
		this.getAllcategory();
		this.getCategoryList(0);
	},
	mounted(){
		mui('.mui-scroll-wrapper').scroll({
			deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
		});
	},
	methods:{
		//从后台数据获取 导航栏列表
		getAllcategory(){
			this.$http.get("photocates.json").then( result =>{
				if(result.body){
					this.cates = result.body;
				}else{
					Toast("获取数据失败！！！");
				}
			})
		},
		getCategoryList(id){
			this.$http.get("photos.json").then(result=>{
				if(result.body){
					console.log(result.body);
					if(id == 0){
						this.list = result.body;
					}else{
						this.list = result.body.filter(item=>{
							if(item.cateid == id){
								return item;
							}
						})
					}
					console.log(this.list);
				}else{
					Toast("获取数据失败!!!");
				}
			})
		}
	},
	
}
</script>
<style lang="scss" scoped>
/* 解决警告加以下样式[Intervention] Unable to preventDefault inside passive event listener due to target being treated as passive. See <URL> */
	/* 是chrom 为了提高滑动流畅度 */
	* { touch-action: pan-y; }
	.photo-list{
		list-style: none;
		margin: 0;
		padding: 10px;
		padding-bottom: 0;

		li{
			background-color: #ccc;
			text-align: center;
			margin-bottom: 10px;
			box-shadow: 0 0 9px #999;
			position: relative;
			
			img{
				width: 100%;
				height: 300px;
			}

			image[lazy=loading] {
				width: 40px;
				height: 300px;
				margin: auto;
			}

			 .info {
				 width: 100%;
				color: white;
				text-align: left;
				position: absolute;
				bottom: 0;
				background-color: rgba(0, 0, 0, 0.4);
				max-height: 84px;
				.info-title {
					font-size: 14px;
				}
				.info-body {
					font-size: 13px;
				}
			 }
		}

	}
	
</style>